import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/// 自定picker
class ShowCupertinoPicker extends StatefulWidget {
  Function confirmBtn;
  List datas;

  ShowCupertinoPicker(
      {
        @required this.confirmBtn,
        @required this.datas});

  @override
  _ShowCupertinoPickerState createState() {
    return _ShowCupertinoPickerState();
  }
}

class _ShowCupertinoPickerState extends State<ShowCupertinoPicker> {
  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {

      return Container(
        color: Colors.white,
        height: 300,
        child: Column(
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                CupertinoButton(
                    child: Text(
                      '取消',
                      style: TextStyle(color: Colors.grey),
                    ),
                    onPressed: (){
                      Navigator.pop(context);
                    }),
                CupertinoButton(child: Text('确定'), onPressed: widget.confirmBtn),
              ],
            ),
            Container(
                height: 243,
                child: CupertinoPicker(
                    backgroundColor: Colors.white,
                    itemExtent: 40,
                    onSelectedItemChanged: (val) {
                      print('The position is $val');
                    },
                    children: List.generate(
                        widget.datas.length,
                            (index) =>
                            Center(child: Text(widget.datas[index]))))),
          ],
        ),
      );

  }
}
